#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
from flask import Flask
from flask import request
from flask import redirect
from flask import jsonify
app = Flask(__name__)

@app.route('/')
def hello_world():
    return jsonify('a,b为数字method为add，mul，sub，div')

@app.route('/api/', methods=[ 'POST'])
def index():
    if request.method == 'POST':
        a = request.get_json()
        if a['method']=='add':
            c = a['a']+a['b']
        elif a['method'] == 'mul':
            c = a['a'] * a['b']
        elif a['method'] == 'sub':
            c = a['a'] - a['b']
        elif a['method'] == 'div':
            c = a['a'] / a['b']
        return jsonify(c)

    else:
        return jsonify('只接受post请求！')

@app.route('/api/v1/a')
def fun1():
    if request.method == 'GET':
        return jsonify({'a': 'a是一个数字'})
    else:
        return jsonify('error')
@app.route('/api/v1/b')
def fun2():
    if request.method == 'GET':
        return jsonify({'b': 'b是一个数字'})
    else:
        return jsonify('error')

@app.route('/api/collection', methods=[ 'POST'])
def fun3():
    return jsonify('c')
@app.route('/api/collection')
def fun4():
    return jsonify('a,,b，m')
@app.route('/api/collection', methods=[ 'PATH'])
def fun5():
        return jsonify('{A,B,M}')
if __name__ =='__main__':
    app.run(debug=True)

